﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class ShowYCDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userName"] == null || Session["roleID"] == null)
        {
            Response.Redirect("Login.aspx");
            Response.End();
        }
        if (!Page.IsPostBack)
        {            
            lblBackUrl.Text = Request.UrlReferrer.ToString();
            BindYCDada();
        }

    }
    /// <summary>
    /// 绑定显示数据
    /// </summary>
    protected void BindYCDada()
    {
        string YCId = Request.QueryString["ycid"].ToString();
        string userName = Session["userName"].ToString();
        string roleID = Session["roleID"].ToString();        
        string dataYear = YCId.Substring(2, 4);
        string tabName = "YCMS" + dataYear;
        string sqlString = "select * from " + tabName + " where YCID='" + YCId + "'";
        DBOperation DBO = new DBOperation();
        SqlDataReader sdr = DBO.GetDataReader(sqlString);
        if (sdr.Read())
        {
            lblYCID.Text = YCId;
            lblTitle.Text = sdr["TITLE"].ToString();
            lblDepName.Text =BasicClass.GetDepNameByDepID(sdr["DEPID"].ToString());
            lblUpUserName.Text = sdr["USERNAME"].ToString();
            lblAddDate.Text=sdr["ADDDATE"].ToString();
            lblCurrentOperator.Text = sdr["CURRENTOPERATER"].ToString();
            lblContent.Text = sdr["CONTENT"].ToString();
            //判断是否显示审核按钮
            if (roleID != "1")
            {
                if (sdr["CURRENTOPERATER"].ToString() != userName)
                {
                    btnCheck.Visible = false;
                }
            }
        }
        //绑定相关附件
        string lblFilesText = "";
        string fileName = "";
        string filePath="";
        Hashtable annexFiles = GetAnnexFiles(YCId);        
        for (int i = 0; i <annexFiles.Count; i++)
        {
            if (annexFiles[i].ToString()!= "")
            {
                fileName = annexFiles[i].ToString();
                fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
                filePath=annexFiles[i].ToString();
                int item = i + 1;
                filePath = Server.UrlEncode(filePath);
                lblFilesText += item.ToString() + "、<a href='DownLoad.aspx?filepath=" +filePath + "'>" + fileName + "</a>,&nbsp;&nbsp;&nbsp;&nbsp;";
            } 
        }
        lblAnnexFiles.Text = lblFilesText;
        sdr.Close();

    }
    protected Hashtable GetAnnexFiles(string YCID)
    {
        Hashtable annexFiles = new Hashtable();
        string dataYear=YCID.Substring(2,4);
        string tableName="YCFILES"+dataYear;
        string sqlString = "select * from " + tableName + " where YCID='" + YCID + "'";
        DBOperation DBO = new DBOperation();
        SqlDataReader sdr = DBO.GetDataReader(sqlString);

        for (int i = 0; sdr.Read();i++ )
        {
            annexFiles[i] = sdr["FILENAME"].ToString();
        }
        sdr.Close();
        return annexFiles;
    }
    protected void btnViewCheckStatus_Click(object sender, EventArgs e)
    {
        Response.Redirect("YCStatusBill.aspx?ycid=" + lblYCID.Text.ToString());

    }
    protected void btnCheck_Click(object sender, EventArgs e)
    {
       Response.Redirect("CheckYC.aspx?ycid=" + lblYCID.Text.ToString());
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        string refURL = "MessageInfo.aspx";

        refURL = lblBackUrl.Text;
        if (refURL == "" || refURL == null || refURL == "MenuDir.aspx")
        {
            refURL = "MessageInfo.aspx";
        }
        Response.Redirect(refURL);

    }
}
